import request from './request'

export const userApi = {
  // 获取用户列表
  getUserList(params) {
    // 转换参数名称：page_size -> pageSize
    const backendParams = {
      page: params.page,
      pageSize: params.page_size || params.pageSize,
      keyword: params.keyword,
      role: params.role,
      status: params.status
    }
    
    return request({
      url: '/user/list',
      method: 'get',
      params: backendParams
    })
  },

  // 获取用户详情
  getUserDetail(id) {
    return request({
      url: `/user/${id}`,
      method: 'get'
    })
  },

  // 更新用户
  updateUser(id, data) {
    return request({
      url: `/user/${id}`,
      method: 'put',
      data
    })
  },

  // 更新用户状态
  updateUserStatus(id, status) {
    return request({
      url: `/user/${id}/status`,
      method: 'put',
      params: { status }
    })
  },

  // 删除用户
  deleteUser(id) {
    return request({
      url: `/user/${id}`,
      method: 'delete'
    })
  },

  // 禁用用户
  banUser(id) {
    return request({
      url: `/user/${id}/ban`,
      method: 'post'
    })
  }
}

